package com.loveprogrammer.eternity.model.game;

import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.model.console.ConsolePrint;
import com.loveprogrammer.eternity.model.product.Coin;
import com.loveprogrammer.eternity.model.product.Equipment;
import com.loveprogrammer.eternity.model.product.Goods;
import com.loveprogrammer.eternity.model.product.Things;
import com.loveprogrammer.eternity.model.product.eggs.Egg;

import java.io.Serializable;
import java.util.*;

/**
 * @version 1.0.0
 * @description: 仓库
 * @author: eric
 * @date: 2022-08-05 17:22
 **/
public class Warehouse implements Serializable {

    /**
     * 最多50个宠物卵
     **/
    private static final int MAX_EGG_NUM = 50;

    /**
     * 最多200件装备
     **/
    private static final int MAX_EQUIPMENT_NUM = 200;

    /**
     * 金币
     **/
    private int goldCoin;

    /**
     * 钻石
     **/
    private int diamonds;

    /**
     * 装备
     **/
    private List<Equipment> equipmentList = new ArrayList<>();

    /**
     * 物品 物品+数量
     **/
    private Map<Integer, List<Things>> things = new HashMap<>();

    /**
     * 宠物卵
     **/
    private List<Egg> eggs = new ArrayList<>();

    public Warehouse() {
    }

    public Warehouse(int goldCoin, int diamonds, List<Equipment> equipmentList, Map<Integer, List<Things>> thingsList, List<Egg> eggs) {
        this.goldCoin = goldCoin;
        this.diamonds = diamonds;
        this.equipmentList = equipmentList;
        this.things = thingsList;
        this.eggs = eggs;
    }

    public void pickUp(List<Goods> fallingGoods) {
        for (Goods good : fallingGoods) {
            if(good instanceof Equipment){
                ConsolePrint.publishMessage("获取装备" + good.prettyPrint());
                equipmentList.add((Equipment) good);
            }

            // 如果是宠物卵
            if(good instanceof Egg) {
                ConsolePrint.publishMessage("获取宠物卵" + good.prettyPrint());
                eggs.add((Egg) good);
            }

            if(good instanceof Things){
                ConsolePrint.publishMessage("获取物品" + good.prettyPrint());
                Things thing = (Things) good;

                if(things.get(thing.getGoods_id()) != null){
                    List<Things> list = things.get(thing.getGoods_id());
                    list.add(thing);
                }else{
                    List<Things> thingsList = new ArrayList<>();
                    thingsList.add(thing);
                    things.put(thing.getGoods_id(), thingsList);
                }

            }
        }
    }

    public void pickUp(Coin fallingCoin) {
        if(fallingCoin != null && (fallingCoin.getGoldCoin()>0 || fallingCoin.getDiamonds()>0)){
            ConsolePrint.publishMessage("获取金钱" + fallingCoin.toString());
            this.goldCoin += fallingCoin.getGoldCoin();
            this.diamonds += fallingCoin.getDiamonds();
            ConsolePrint.publishMessage("总计：\t" +
                    " 钻石：" + this.diamonds + "\t" +
                    " 金币：" + this.goldCoin + "\t");
        }
    }

    public int getGoldCoin() {
        return goldCoin;
    }

    public void setGoldCoin(int goldCoin) {
        this.goldCoin = goldCoin;
    }

    public int getDiamonds() {
        return diamonds;
    }

    public void setDiamonds(int diamonds) {
        this.diamonds = diamonds;
    }

    public List<Equipment> getEquipmentList() {
        return equipmentList;
    }

    public void setEquipmentList(List<Equipment> equipmentList) {
        this.equipmentList = equipmentList;
    }

    public Map<Integer, List<Things>> getThingsList() {
        return things;
    }

    public void setThingsList(Map<Integer, List<Things>> things) {
        this.things = things;
    }

    public List<Egg> getEggs() {
        return eggs;
    }

    public void setEggs(List<Egg> eggs) {
        this.eggs = eggs;
    }
}
